const fs =require("fs")
const path = require("path")
//一行一行读
const readline = require("readline")
//文件名
const fullname = path.join(__dirname,'../','logs/','access.log')
//创建read stream
const readStream = fs.createReadStream(fullname)
//创建readline对象
const rl = readline.createInterface({
  input : readStream
})

let chromeNum = 0
let num = 0
rl.on('line',function(linedata){
  if(!linedata){
    return 
  }
  //记录总行数
  num++;
  const arr = linedata.split(' -- ')
  if(arr[2]&&arr[2].indexOf('Chrome')>=0){
    //累加chrome的数量
    chromeNum++
  }
})
//监听读取完成
rl.on('close',()=>{
  let per = (chromeNum/num)
  let per1 = per*100+'%'
  console.log('chrome 占比'+per1);
  
})
